//@author A0105735J
#include "CommandDelete.h"

CommandDelete::CommandDelete(void){
	type = CommandTypeDelete;
}

CommandDelete::~CommandDelete(void){}

void CommandDelete::setID(std::vector<int> id){
	deleteID.clear();
	while(!id.empty()){
		deleteID.push_back(id.back());
		id.pop_back();
	}
}

Feedback CommandDelete::execute(Receiver* receiver){
	Logger::instance()->LogMessage("trying to delete one event");	
	std::vector<int>::iterator iter;
	for(iter = deleteID.begin(); iter != deleteID.end(); iter++){
		undoDeleteEvent.push_back(receiver->getTargetEvent(*iter,1));
	}		
	return receiver->deleteCommand(deleteID);
}

Feedback CommandDelete::undo(Receiver* receiver){
	Logger::instance()->LogMessage("trying to add one event which was deleted just now");	
	Feedback output;
	output.storeUpdateCalendar(undoDeleteEvent);
	std::vector<Event*>::iterator iter;
	// add all the events in the undoDeleteEvent
	for(iter = undoDeleteEvent.begin(); iter != undoDeleteEvent.end(); iter++){	
		receiver->addCommand(*iter);	
	}
	return output;
}